﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using SRecordizer.Objects;


namespace UpgadeFileCombineApp
{
    public partial class SRecordView
    {
       
        S19 _S19Record;
        public Byte[] AppImage;
        
        /*********************************************************************/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="newFile"></param>
        public SRecordView(string filename, bool newFile,  int bootSize)
        {
            try
            {
                int cnt_ff = 0;
                FileInfo info = new FileInfo(filename);
                _S19Record = new S19(filename, newFile);  //解析
                int bootsize = bootSize;
                AppImage = _S19Record.ListByteImage.ToArray();

                int i = AppImage.Length - 1;  
                while (true)
                {
                    if (AppImage[i--] == 0xff)   //去掉文件后面连续的FF
                    {
                        cnt_ff++;
                    }
                    else
                    {
                        break;
                    }
                }
 
               
                byte[] resArr = new byte[AppImage.Length - bootsize- cnt_ff];
                Array.Copy(AppImage, bootsize, resArr, 0, AppImage.Length - bootsize- cnt_ff);  //去掉前面boot镜像,去掉后面连续FF,截取中间app impage
                AppImage = resArr; 
                
            }

            catch
            {
                throw new Exception(".mot文件错误解析失败!");
            }
        }
    }
}
